package edu.uab.enronemail.factory;

import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;

public class ElasticSearchClientFactory {
	
	static Client client = null;
	static String localhost="127.0.0.1";
	
	/**
	 * TODO Pass property read from an external property file
	 * @return Client for the elasticsearch cluster
	 */
	public static Client getClient() {
		if (client == null) {
			Settings settings = ImmutableSettings.settingsBuilder()
					.put("cluster.name", "elasticsearch").build();
			client = new TransportClient(settings).addTransportAddress(
					new InetSocketTransportAddress(localhost, 9300))
					.addTransportAddress(
							new InetSocketTransportAddress(localhost, 9301))
							.addTransportAddress(new InetSocketTransportAddress(localhost,9302));
		}
		return client;
	}
	
	
	
	
}
